import Vue from 'vue'
import App from './App.vue'
// import 'lib-flexible'
import Vant from 'vant';
import 'vant/lib/index.css';
import axios from 'axios';
import VCharts from 'v-charts-v2'
import store from './store'
import router from './router'
import Qs from 'qs'
import VueClipboard from 'vue-clipboard2'
import VueI18n from 'vue-i18n'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import './assets/css/comm.css'
Vue.use(VueI18n) // 通过插件的形式挂载
Vue.use(VCharts)

console.log('-----store.getters.language-------',store.getters.language);
const i18n = new VueI18n({
	locale: store.getters.language || 'zh-CN',    // 语言标识
	//this.$i18n.locale // 通过切换locale的值来实现语言切换
	messages: {
		'zh-CN': require('./lang/zh'),   // 中文语言包
		'en-US': require('./lang/en')    // 英文语言包
	}
})
VueClipboard.config.autoSetContainer = true
Vue.use(VueClipboard)
Vue.config.productionTip = false
Vue.use(Vant);
Vue.prototype.$axios = axios;
Vue.prototype.qs = Qs;
Vue.prototype.$post = post;
Vue.prototype.$get = get
NProgress.configure({
	easing: 'ease',  // 动画方式    
	speed: 500,  // 递增进度条的速度    
	showSpinner: false, // 是否显示加载ico    
	trickleSpeed: 200, // 自动递增间隔    
	minimum: 0.3 // 初始化时的最小百分比
})

router.beforeEach((to, from, next) => {
	// 每次切换页面时，调用进度条
	NProgress.start();
	next();
});


router.afterEach(() => {
	// 在即将进入新的页面组件前，关闭掉进度条
	NProgress.done()
})
const root = "https://app.dcgint.net/";
// const root = "https://api.xingrunkeji.cn/tronstar/";
// const root = process.env.VUE_APP_SERVE_URL
function url(a) {
	var url = root + a;
	return url
}
function get(obj) {
	let postData = obj.data;
	let api = url(obj.url);
	return new Promise((resolve, reject) => {
		axios.get(api, {params:postData,headers:{token:'1'}}).then(res => {
			if (res.data) {
				obj.callback(res.data);
			}
		}).catch(err => {
			reject(err)
		});
	})
}

function post(obj) {
	let postData = obj.data;
	let api = url(obj.url);
	return new Promise((resolve, reject) => {
		axios.post(api, postData,{headers:{'token': '1'}}).then(res => {
			if (res.data) {

				obj.callback(res.data);
			}
		}).catch(err => {
			reject(err)
		});
	})
}
new Vue({
	store,
	i18n,
	router,
	render: h => h(App),
}).$mount('#app')
